{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "def bound(true, l, r):      # last number makes true in [l, r)\n",
    "    if r - l == 0 or not true(l):\n",
    "        return -1           # no number makes true\n",
    "    \n",
    "    while r - l > 1:\n",
    "        m = (l + r) // 2\n",
    "\n",
    "        if true(m):\n",
    "            l = m\n",
    "        else:\n",
    "            r = m\n",
    "\n",
    "    return l"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "base",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.9.12 (main, Apr  4 2022, 05:22:27) [MSC v.1916 64 bit (AMD64)]"
  },
  "orig_nbformat": 4,
  "vscode": {
   "interpreter": {
    "hash": "3a176caed2e623e3a36a87b094ae4f1cc68623d3a88a2d36a2ea84f7c5d7277a"
   }
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
